class TestController < ApplicationController

  def testSubQuery
    purchases =  Purchase.find(:all, :conditions => "id in (select purchase_id from offers where vendor_id = 1)")
    logger.info purchases.size
    logger.info purchases[0].quantity
  end

  def testCount
    applicants = Applicant.all

    applicants.each do |applicant|
      department = Department.find(:first,:conditions=>['number = ?',applicant.department_id])
      applicant.department_id = department.id
      applicant.save
    end
    #    departments = Department.all
    #    departments.each do |department|
    #      department.number = '109'+department.number
    #      department.save
    #    end
  end

  def round
    logger.info 4.5.round
  end

  #For Rails 3.0
  def saveCA
    begin
      sysControllers = {}
      con_classes = ObjectSpace.each_object(Class).select {|cls| cls.ancestors[1..-1].include?(ApplicationController) }
      con_classes.each do |cls|
        controller = cls.to_s.underscore
        puts "controller--------------------------------"
        controller =  controller.gsub("_controller","")
        puts controller
        if controller != "test"
          ctrl = SysController.find(:first,:conditions=>["name = ?",controller])
          if ctrl == nil
            ctrl = SysController.new
            ctrl.name = controller.to_s
          end
          puts ctrl.name
          methodsArray = cls.public_instance_methods(false)
          methodsArray = methodsArray.find_all{|n| n.index("_") != 0}
          for sysMethod in methodsArray
            action = SysAction.find(:first,:conditions=>["name = ? AND sys_controller_id = ?",sysMethod.to_s,ctrl.id])
            if action == nil
              action = SysAction.new
              action.name = sysMethod.to_s
              ctrl.sys_actions << action
            end
          end
          ctrl.save!
        end
      end
    rescue Exception => e
      logger.info "logging......................................................................................."
      DbLog.info(params[:controller], params[:action], request.remote_ip ,e.to_s)
      logger.info e
    end
  end
end
